package com.telit.firecommand.service;

import com.telit.common.vo.user.SysUserDetailVo;
import com.telit.firecommand.dao.FireDisposalInfoDao;
import com.telit.firecommand.dto.RecordScene;
import com.telit.firecommand.entity.FireDisposalInfo;
import com.telit.upms.vo.MicroSysUserAllInfoVo;
import com.telit.upms.vo.MicroSysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Auther zhouyu
 * @description 火情处置接口
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public abstract class FireDisposeService {

    @Autowired
    private FireDisposalInfoDao fireDisposalInfoDao;



    /**
     * 插入数据库
     * @param fireDisposalInfo
     */
    private void insertFireDisposeInfo(FireDisposalInfo fireDisposalInfo){
        fireDisposalInfo.setDisposeTime(new Date());
        fireDisposalInfoDao.insert(fireDisposalInfo);
    }

    /**
     * 生成处置意见
     * @param recordScene
     * @return
     */
    public abstract String generateDisposeInfo(RecordScene recordScene);

    /**
     * 处置
     * @param recordScene
     */
    public void processDisposeInfo(RecordScene recordScene, MicroSysUserAllInfoVo microSysUserVo){
        String disposalInfo = generateDisposeInfo(recordScene);
        FireDisposalInfo fireDisposalInfo = new FireDisposalInfo();
        fireDisposalInfo.setDisposeTime(new Date());
        if(microSysUserVo!=null) {
            fireDisposalInfo.setDisposePerson(microSysUserVo.getRealName());
            fireDisposalInfo.setDisposeOrg(microSysUserVo.getDeptName());
        }
        fireDisposalInfo.setDisposeOpinion(disposalInfo);
        fireDisposalInfo.setFireId(recordScene.getFireId());
        insertFireDisposeInfo(fireDisposalInfo);
    }
}
